// pages/index/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        height:200,
        typeid:2,
        typeList:[
            { id: 1, name: '优惠' },
            { id: 2, name: '优惠' },
            { id: 3, name: '优惠' },
            { id: 4, name: '优惠' },
            { id: 5, name: '优惠' }
        ],
        item:[
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
            { id: 1, name: '精品豆浆', cost: '1.00' },
        ],
        animation:null,
        animation_bg:null,
        carthide:true
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var $this = this;
        var height = wx.getSystemInfoSync().windowHeight;
        var query = wx.createSelectorQuery();
        query.select('#addrs').boundingClientRect();
        query.exec(function (res) {
            console.log(res);
            $this.setData({
                height: height - res[0].height
            });
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },
    showCostCart:function(){
        console.log(2);
        var $this = this;
        this.setData({
            carthide: false
        });
        var height = wx.getSystemInfoSync().windowHeight;
        var query = wx.createSelectorQuery();
        query.select('#cartv').boundingClientRect();

        query.exec(function (res) {
            console.log(res);
            var animation = wx.createAnimation({
                transformOrigin: "50% 50%",
                duration: 300,
                timingFunction: "ease-out",
                delay: 0
            })
            $this.animation = animation
            animation.translateY(0).step()
            $this.setData({ 
                animation: animation.export(),
            })

            animation = wx.createAnimation({
                transformOrigin: "50% 50%",
                duration: 300,
                timingFunction: "ease-out",
                delay: 0
            })
            $this.animation = animation
            animation.opacity(1).step()
            $this.setData({
                animation_bg: animation.export(),
            })

        });
    },
    hideCostCart:function(e){
        var $this = this;
        var height = wx.getSystemInfoSync().windowHeight;
        var query = wx.createSelectorQuery();
        query.select('#cartv').boundingClientRect();
        query.exec(function (res) {
            console.log(res);
            var animation = wx.createAnimation({
                transformOrigin: "50% 50%",
                duration: 300,
                timingFunction: "ease-out",
                delay: 0
            })
            $this.animation = animation
            animation.translateY(res[0].height).step()
            $this.setData({
                animation: animation.export(),
            })

            animation = wx.createAnimation({
                transformOrigin: "50% 50%",
                duration: 300,
                timingFunction: "ease-out",
                delay: 0
            })
            $this.animation = animation
            animation.opacity(0).step()
            $this.setData({
                animation_bg: animation.export(),
            })
            setTimeout(function(){
                $this.setData({
                    carthide: true
                });
            },300);
        });
    }
})